package com.gmrz.uaf.db;

import com.gmrz.uaf.common.UAFBaseModule;
import com.gmrz.uaf.common.UAFRuntimeException;
import com.gmrz.uaf.db.dao.*;
import com.gmrz.webauthn.db.dao.*;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Properties;

public class UAFDBModule extends UAFBaseModule {

    private static final Logger LOG = LogManager.getLogger(UAFDBModule.class);

    public UAFDBModule(Properties dbProperties) {
        super(dbProperties);

        if (dbProperties == null) {
            String errorMessage = "Module properties object cannot be null.";
            LOG.error(errorMessage);
            throw new UAFRuntimeException(errorMessage);
        }

    }

    protected void configure() {

        super.configure();
        install(new FactoryModuleBuilder().implement(AuthenticatorDAO.class, BaseAuthenticatorDAO.class)
                .implement(AuthenticatorSpecDAO.class, BaseAuthSpecDAO.class)
                .implement(DevicesDao.class, BaseDevicesDAO.class)
                .implement(UasConfigDAO.class, BaseUasConfigDAO.class)
                .implement(WhiteListDAO.class, BaseWhiteListDAO.class)
                .implement(FidoLogDAO.class, BaseFidoLogDAO.class)
                .implement(ServicePluginDAO.class, BaseServicePluginDAO.class)
                .implement(PluginDataDAO.class, BasePluginDataDAO.class)
                .implement(WebAuthnAuthenticatorsDAO.class, BaseWebAuthnAuthenticatorDAO.class)
                .implement(WebAuthnPolicyDAO.class, BaseWebAuthnPolicyDAO.class)
                .implement(TenantConfigDAO.class, BaseTenantConfigDAO.class)
                .implement(FacetsDAO.class, BaseFacetsDAO.class)
                .implement(WebAuthnMetadataDAO.class, BaseWebAuthnMetadataDAO.class)
                .build(DAOFactory.class));
    }
}
